<?php

	$words = $_POST['words'];

	print_r($words);

	//文件被清空后再写入
	$fp = fopen("data.json", "w");

	if($fp) {

		$content = "var words=[";
		for ($i=0; $i < count($words); $i++) { 
			# code...
			$content .= '"'.$words[$i].'",';
		}

		$content = rtrim($content, ",");

		$content .= "];";
		$flag=fwrite($fp, $content); 
		if(!$flag) { 
			echo "写入文件失败<br>"; 
			break; 
		} 
	}
	else{
		echo "打开文件失败"; 
	} 

	fclose($fp); 


?>